<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class LoginController extends Controller{
		public function index(){
			if(IS_POST){
				//1.接收用户名
				//$username = Q('post.username');	
				$email = Q('post.email');
				//$phone = Q('post.phone');	
				//2.接收密码
				$password = Q('post.password','','md5');
				//p($password);die;
				//3.判断用户名是否存在
				$model = new \Common\Model\User;
				//$data = $model->where("username = '{$username}'")->find();
				$datas = $model->where("email = '{$email}'")->find();
				//p($datas);
				//如果从数据库里查不出数据说明此用户名不存在
				if(!$datas) View::error('用户名或密码不正确');
				//4.判断密码是否正确
				if($datas['password'] != $password) View::error('用户名或密码不正确');
				//5.登陆成功
				//如果以上判断都对了，说明此用户存在且密码正确
				//把$data里的uid和username存入session
				$_SESSION['uid'] = $datas['uid'];
				$_SESSION['email'] = $datas['email'];
				View::success('登录成功',U('Index/index'));
			}
			//载入模板
			View::make();
		}
		//退出删除和销毁session跳转到登陆首页
	public function out(){
		session_unset();
		session_destroy();
		View::success('退出成功');
		go(U('Index/index'));
	}

}








?>




 